package com.sinoglobal.sinostore.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.sinoglobal.sinostore.R;
import com.sinoglobal.sinostore.bean.CollectionVo;
import com.sinoglobal.sinostore.utils.BitmapHelp;
import com.sinoglobal.sinostore.utils.TextUtil;

public class CollectionAdapter extends AbBaseAdapter<CollectionVo> {

	BitmapUtils bitmapUtils;
	String imgHost;
	public void setImgHost(String imgHost) {
		this.imgHost = imgHost;
		notifyDataSetChanged();
	}
	public CollectionAdapter(Context context, List<CollectionVo> data) {
		super(context, R.layout.shop_collection_list_item, data);
		bitmapUtils=BitmapHelp.getBitmapUtils(context);
	}

	@Override
	void setView(int position, View convertView) {
		CollectionVo collectionVo=getItem(position);
		
		ImageView ivPic=ViewHolder.getViewById(convertView, R.id.ivPic);
		bitmapUtils.display(ivPic,imgHost+collectionVo.getImg_url());
		
		TextView tvCollectionName=ViewHolder.getViewById(convertView, R.id.collectionName);
		tvCollectionName.setText(collectionVo.getName());
		
		TextView tvCollectionTime=ViewHolder.getViewById(convertView, R.id.collectionTime);
		tvCollectionTime.setVisibility(View.GONE);;
		
		TextView tvPrice=ViewHolder.getViewById(convertView, R.id.price);
		if(TextUtil.isZeroOrNull(collectionVo.getPrice()) && !TextUtil.isZeroOrNull(collectionVo.getCash())){//积分单价为零，现金不为零，为现金支付
			tvPrice.setText(String.format("￥%s元", collectionVo.getCash()));
		}else if(TextUtil.isZeroOrNull(collectionVo.getCash()) && !TextUtil.isZeroOrNull(collectionVo.getPrice())){//现金单价为零，为积分支付
			tvPrice.setText(String.format("%s%s", collectionVo.getPrice(),context.getString(R.string.score_unit)));
		}else{//两个都不为零则为现金加积分支付
			tvPrice.setText(String.format("￥%s元+%s%s", collectionVo.getCash(),collectionVo.getPrice(),context.getString(R.string.score_unit)));
		}
	}

}
